package com;

/**
 * Created by THINK on 2016/7/4.
 * http://www.tuicool.com/articles/7VRBZj
 */
public class UnsignedTest {

    public static void main(String[] args) {
        byte b = (byte) 255;
        //b>=0 && b< =255
        System.out.println("b1=" + b);
        System.out.println("b2=" + (b & 0xff));
        //-------------------------------
        short ss = (short) 65535;
        //ss>=0 && ss< =65535
        System.out.println("ss=" + ss);
        int rr = (ss) & 0xffff;
        System.out.println("rr=" + rr);
        //使用例子：
        byte[] bb = new byte[2];
        bb[0] = (byte) (ss >> 0);
        bb[1] = (byte) ((ss >> 8));
        int result = ((short) ((bb[0] & 0xff) | (bb[1]) << 8)) & 0xffff;
        System.out.println("result=" + result);
        //-------------------------------
        long ll = 4294967295L;
        //ll>=0 && ll< =4294967295L
        int ii = (int) ll;
        System.out.println("ii=" + ii);
        long l2 = (ii & 0xffffffffL);//0xffffffffffffffffL
        System.out.println("l2=" + l2);
    }
}
